package com.sky.controller.admin;

import com.sky.dto.*;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController("adminOrderController")
@RequestMapping("/admin/order")
@Api("C-订单类接口")
@Slf4j
public class OrderController {
    @Autowired
    private OrderService orderService;
    @PutMapping("/cancel")
    @ApiOperation(value = "取消订单")
    public Result cancelOrder(@RequestBody OrdersCancelDTO ordersCancelDTO) {
        orderService.aminCancelByDTO(ordersCancelDTO);
        return Result.success(); // 返回成功结果
    }

    @GetMapping("/statistics")
    @ApiOperation(value = "获取订单状态统计")
    public Result<OrderStatisticsVO> getOrderStatistics() {
        OrderStatisticsVO orderStatisticsVO = orderService.getOrderStatistics();
        return Result.success(orderStatisticsVO); // 返回成功结果
    }

    @PutMapping("/complete/{id}")
    @ApiOperation(value = "完成订单")
    public Result completeOrder(@PathVariable  Long id) {
        orderService.completeOrder( id);
        return Result.success(); // 返回成功结果
    }

    @PutMapping("/rejection")
    @ApiOperation(value = "拒单")
    public Result rejectOrder(@RequestBody OrdersRejectionDTO ordersCancelDTO) {
        orderService.rejectOrder(ordersCancelDTO);
        return Result.success();
    }

    @PutMapping("/confirm")
    @ApiOperation(value = "接单")
    public Result confirmOrder(@RequestBody OrdersConfirmDTO ordersConfirmDTO) {
        orderService.confirmOrder(ordersConfirmDTO.getId());
        return Result.success();
    }

    @GetMapping("/details/{id}")
    @ApiOperation(value = "查询订单详情")
    public Result<OrderVO> getOrderDetails(@PathVariable Long id) {
        return Result.success(orderService.detail(id));
    }

    @PutMapping("/delivery/{id}")
    @ApiOperation(value = "派送订单")
    public Result deliveryOrder(@PathVariable Long id) {
        orderService.deliveryOrder(id);
        return Result.success();
    }

    @GetMapping("/conditionSearch")
    @ApiOperation(value = "订单搜索")
    public Result<PageResult> searchOrders(OrdersPageQueryDTO ordersPageQueryDTO) {
        return Result.success(orderService.searchOrders(ordersPageQueryDTO));
    }

}